package com.fingard.dsp.bank.reqrespobj.batpayrec;

import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.single.detail.RetAtsSglDetail;
import com.fingard.xml.XmlTextWriter;

/**
 * 普通单笔支付提交或查询返回ATS通用响应对象
 * 
 * @author Cruise
 * @date 2019/6/20
 */
public class RetAtsBatPayRec extends RetAtsBase {
	/** 通讯响应码 */
	public String respCode;
	
	/** 通讯响应信息 */
	public String respInfo;
	
	/** 支付状态 */
	public String transState;
	
	/** 支付信息码 */
	public String payInfoCode;
	
	/** 支付批次号 */
	public String reqSeqID;
	
	/** 新支付批次号 */
	public String newReqSeqID;

	public RetAtsBatPayRec(ReqRespHeader p_header) {
		retHeader = p_header;
		retXmlWriter = new XmlTextWriter();
	}
	
	public RetAtsBatPayRec(ReqBatPayRec tmpBatReq) {
		retHeader = tmpBatReq.reqHeader;
		retXmlWriter = new XmlTextWriter();
		reqSeqID = tmpBatReq.reqBatchNO;
	}

	public void writeRetToATS() {
		writeStart();
		retXmlWriter.writeStartElement("DetailRecord");
		retXmlWriter.writeElementString("NewReqSeqID", newReqSeqID);
		retXmlWriter.writeElementString("RespCode", respCode);
		retXmlWriter.writeElementString("RespInfo", respInfo);
		retXmlWriter.writeElementString("TransState", transState);
		retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
		retXmlWriter.writeElementString("PayInfoCode", payInfoCode);
		retXmlWriter.writeEndElement();
		writeEnd();
	}

	/**
	 * 批量转单笔
	 */
	public RetAtsSglDetail convertToSingle() {
		RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
		tmpRetDetail.reqSeqID = this.reqSeqID;
		tmpRetDetail.respCode = this.respCode;
		tmpRetDetail.respInfo = this.respInfo;
		tmpRetDetail.transState = this.transState;
		tmpRetDetail.payInfoCode = this.payInfoCode;
		return tmpRetDetail;
	}

	public void fillBatchFailed(ReqBatPayRec tmpBatReq, String p_failCode,
			String p_failMsg) {
		respCode = "0";
		reqSeqID = tmpBatReq.reqBatchNO;
		transState = PaymentState.FAIL_Batch;
		payInfoCode = p_failCode;
		respInfo = p_failMsg;
	}
}